// pages/goodsdetails/goodsdetails.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: [],
        GroupBookingmessage: [],
        id: '',
        addresslist:[],
        stare:false,
        type:'',
        ids:''
    },
    //选择收货地址后执行对应的操作
    groupbookingorder()
    {
        var that = this
        var id=that.data.ids
        if(that.data.type == 9){
            wx.request({
                url: 'http://fbj.wdmnm.vip/api/wxGroupBookingAddition',
                data: {
                    id: id,
                    uid: wx.getStorageSync('uid'),
                    token: wx.getStorageSync('token')
                },
                dataType: 'json',
                success: function (res) {
                    var id=res.data.data
                    if (res.data.code != 200) {
                        wx.showToast({
                          title: res.data.msg,
                          icon:'none',
                          duration:2000
                        })
                    } else {
                        wx.showToast({
                          title: res.data.msg,
                          icon:'success',
                          duration:2000,
                          success:function(){
                            setTimeout(function(res){
                              wx.redirectTo({
                                url: '/pages/groupbookingdetails/groupbookingdetails?id=' + id,
                              })
                            },2000)
                          }
                        })
                    }
    
                }
            })
        }else{
            wx.request({
                url: 'http://fbj.wdmnm.vip/api/wxGroupBookingAdd',
                data: {
                    id: id,
                    uid: wx.getStorageSync('uid'),
                    token: wx.getStorageSync('token')
                },
                dataType: 'json',
                success: function (res) {
                    var id=res.data.data
                    if (res.data.code != 200) {
                        wx.showToast({
                          title: res.data.msg,
                          icon:'none',
                          duration:2000
                        })
                    } else {
                        wx.showToast({
                          title: res.data.msg,
                          icon:'success',
                          duration:2000,
                          success:function(){
                            setTimeout(function(res){
                              wx.redirectTo({
                                url: '/pages/groupbookingdetails/groupbookingdetails?id=' + id,
                              })
                            },2000)
                          }
                        })
                    }
    
                }
            })
        }
    },
    //加入别人的团
    wxGroupBookingAddition(e)
    {
        var id = e.currentTarget.id
        var that = this
        that.setData({
            stare:true,
            type:9,
            ids:id
        })
        
    },
    //发起拼团
    launchgroupbooking(e) {
        var id = e.currentTarget.id
        var that = this
        that.setData({
            stare:true,
            type:8,
            ids:id
        })
       
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var id = options.id
        var that = this
        wx.request({
            url: 'http://fbj.wdmnm.vip/api/wxGoodsDetails',
            data: {
                id: id,
                uid: wx.getStorageSync('uid'),
                token: wx.getStorageSync('token')
            },
            dataType: 'json',
            success: function (res) {
                console.log(res.data.data);
                if (res.data.code == 200) {
                    that.setData({
                        list: res.data.data.goodsdetails,
                        GroupBookingmessage: res.data.data.GroupBookingmessage,
                        id: id,
                        address:res.data.data.address.data
                    })
                }
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})